package cn.shanke.torrentmanagerserver.controller.common;

import com.alibaba.fastjson.JSON;
import lombok.Data;

@Data
public class ResponseModel {

    public static final int CODE_SUCCESS = 1;
    public static final int CODE_FAILURE = 0;
    public static final int CODE_NO_AUTH = 50001;

    private int code;
    private String message;
    private Object data;

    public ResponseModel(int code, String message, Object data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    public ResponseModel message(String message) {
        this.setMessage(message);
        return this;
    }

    public ResponseModel data(Object data) {
        this.setData(data);
        return this;
    }

    public String toJsonString() {
        return  JSON.toJSONString(this);
    }

    public static ResponseModel success(){
        return new ResponseModel(CODE_SUCCESS, null, null);
    }

    public static ResponseModel failure(String message){
        return new ResponseModel(CODE_FAILURE, message, null);
    }

    public static ResponseModel model(int code, String message){
        return new ResponseModel(code, message, null);
    }
}
